package com.hxt.repository;

import com.hxt.entity.User;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.persistence.Table;

/**
 * 这里面是创建一个UserRepository接口，并不需要创建UserRepository实现，
 * springboot默认会帮你实现，继承自CrudRepository.
 * @Param 代表的是sql语句中的占位符，例如这里的@Param(“name”)代表的是:name占位符。
 * Created by Huangxiutao on 2017/3/31.
 */
@Repository
@Table(name="user")
@Qualifier("userRepository")
public interface UserRepository extends CrudRepository<User,Long> {
    public User findUserById(Long id);

    public User save(User user);

    @Query("from User t where t.userName=:name")
    public User findByUserName(@Param("name")String userName);

}
